﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace parkMonitor.model {
	/// <summary>设备Xml配置类</summary>
	public class EquipmentsSection : IConfigurationSectionHandler {
		Dictionary<string, EquipmentSection> mapData = new Dictionary<string, EquipmentSection>();
		public EquipmentSection this[string key] {
			get {
				if(!mapData.ContainsKey(key)) {
					return null;
				}
				return mapData[key];
			}
		}

		public object Create(object parent, object configContext, XmlNode section) {
			foreach(XmlNode node in section.ChildNodes) {
				if(node.NodeType != XmlNodeType.Element) {
					continue;
				}
				EquipmentSection childMd = new EquipmentSection() {
					 key = node.Attributes["key"].Value,
					 value = node.Attributes["value"].Value
				};
				mapData[childMd.key] = childMd;
			}
			return this;
		}
	}

	public class EquipmentsSections : ConfigurationSection {
		[ConfigurationProperty("Equipments", IsDefaultCollection = false)]
		[ConfigurationCollection(typeof(EquipmentsSection), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
		public EquipmentsSection Equipments {
			get {
				return (EquipmentsSection)base["Equipments"];
			}
		}
	}

	public class EquipmentSection {
		public string key;
		public string value;
	}
}
